package com.gzlz.budejie.activity;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

import com.gzlz.budejie.R;
import com.gzlz.budejie.fragment.Guanzhu;
import com.gzlz.budejie.fragment.Jinghua;
import com.gzlz.budejie.fragment.Wode;
import com.gzlz.budejie.fragment.Zuixin;

public class MainActivity extends FragmentActivity {

	ArrayList<Fragment> frs = new ArrayList<Fragment>();
	private int last;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		frs.add(new Jinghua());
		frs.add(new Zuixin());
		frs.add(new Guanzhu());
		frs.add(new Wode());
		FragmentTransaction bt = getSupportFragmentManager().beginTransaction();
		bt.add(R.id.fr_main, frs.get(0));
		last = 0;
		bt.commit();
	}
	
	public void 切换(int index){
		if (index!=last) {
			FragmentTransaction bt = getSupportFragmentManager().beginTransaction();
			bt.remove(frs.get(last));
			bt.add(R.id.fr_main, frs.get(index));
			last = index;
			bt.commit();
		}
	}
	
	
	
}
